package com.dmz.insclient.service;

import java.text.DecimalFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.List;

import cn.hutool.json.JSONArray;
import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import com.dmz.insclient.utils.StringUtil;
import com.dmz.insclient.utils.XmlJsonUtil;
import com.dmz.insclient.po.Info;

/**
 * @author lee
 */
public class JieXiMes {

    public String deal(String sbxml1, String sbxml2, String headXml) {
        String rebocXml = "";
        String Aae003 = "";// 循环
        String Aae004 = "";// 循环
        String Aaa041 = "";// 循环
        String Aae020 = "";// 循环
        String Aae022 = "";// 循环
        String Aaa042 = "";// 循环
        String Aae002 = "";// 循环
        String Aae080 = "";// 循环
        String Aae082 = "";// 循环
        String AC041 = "";// 单位缴费基数
        String AC051 = "";// 个人缴费基数
        String AC042 = "";// 单位缴费基数
        String AC052 = "";// 个人缴费基数
        String TMP = "";// 单位应缴金额临时字段
        boolean code1Flag = false;
        boolean code2Flag = false;
        String cp1 = "";
        String af1 = "";
        String cp2 = "";
        String af2 = "";
        int LoopsCount1 = 0;
        int LoopsCount2 = 0;
        Date dy1 = null;
        Date dy2 = null;
        DecimalFormat myde = new DecimalFormat("#.00");
        StringUtil sutil = new StringUtil();
        JSONObject recodejson = null;
        JSONObject recodejson2 = null;
        SimpleDateFormat sdf = new SimpleDateFormat("yyyyMM");
        Calendar cal = new GregorianCalendar();
        cal.setTime(new Date());
        cal.add(cal.MONTH, -1);
        try {
            if (!"null".equals(sbxml1)) {
                String b1 = XmlJsonUtil.xml2json(sbxml1);
                JSONObject result = JSONUtil.parseObj(b1);
                JSONObject o2 = JSONUtil.parseObj((String) result.getStr("MsgText"));
                JSONObject o3 = JSONUtil.parseObj((String) o2.getStr("BusiText"));
                recodejson = JSONUtil.parseObj((String) o3.getStr("Rst"));
                LoopsCount1 = o3.getInt("LoopCount");

                if ("0000".equals(recodejson.get("Code"))) {
                    JSONObject o4 = JSONUtil.parseObj((String) o3.getStr("Loops"));
                    List<Object> jsonarray = o4.getJSONArray("Loop");
                    String jsonString = JSONUtil.toJsonStr(jsonarray);
                    JSONArray ls = JSONUtil.parseArray(jsonString);
                    List<Info> info = new ArrayList<>();
                    ls.stream().forEach(l -> {
                        Info bean = JSONUtil.toBean(JSONUtil.parseObj(l), Info.class);
                        info.add(bean);
                    });

                    String strattime = "";

                    // strattime =
                    // sdf.format(sutil.getMonthDate(sdf.parse(info.get(0).getAae003()),
                    // 1));//开始月份

                    strattime = sdf.format(cal.getTime());// 开始月份
                    List<String> list = sutil.getMonths(sdf.format(sutil.getMonthDate(sdf.parse(strattime), -24)),
                            strattime);// 24个月之前

                    boolean flag = false;
                    List<String> infoReserve = new ArrayList<String>();
                    for (int i = list.size() - 1; i >= 0; i--) {// 倒序月份
                        infoReserve.add(list.get(i));
                    }
                    for (String s : infoReserve) {// 循环loop
                        flag = false;
                        for (int i = 0; i < info.size(); i++) {
                            if (s.toString().contains(info.get(i).getAae003())) {


                                if (info.get(i).getAaa041().equals("0")) {
                                    continue;
                                } else if (info.get(i).getAaa042().equals("0")) {
                                    Aaa042 += "16.00%|";
                                    Aaa041 += myde.format(Double.parseDouble(info.get(i).getAaa041()) * 100) + "%|";
                                    Aae020 += "0|";
                                    Aae022 += StringUtil.yihuo(info.get(i).getAae022()) + "|";
                                    Aae002 += info.get(i).getAae002() + "01|";
                                    Aae003 += info.get(i).getAae003() + "|";
                                    Aae080 += jfzt2type(info.get(i).getAae003(), info.get(i).getAae002()) + "|";
                                    Aae082 += jfzt2type(info.get(i).getAae003(), info.get(i).getAae002()) + "|";
                                    AC041 = StringUtil.yihuo(info.get(0).getAab121());
                                    AC051 = StringUtil.yihuo(info.get(0).getAab120());
                                    flag = true;
                                } else {
                                    Aaa042 += myde.format(Double.parseDouble(info.get(i).getAaa042()) * 100) + "%|";
                                    Aaa041 += myde.format(Double.parseDouble(info.get(i).getAaa041()) * 100) + "%|";
                                    Aae020 += StringUtil.yihuo(info.get(i).getAae020()) + "|";
                                    Aae022 += StringUtil.yihuo(info.get(i).getAae022()) + "|";
                                    Aae002 += info.get(i).getAae002() + "01|";
                                    Aae003 += info.get(i).getAae003() + "|";
                                    Aae080 += jfzt2type(info.get(i).getAae003(), info.get(i).getAae002()) + "|";
                                    Aae082 += jfzt2type(info.get(i).getAae003(), info.get(i).getAae002()) + "|";
                                    AC041 = StringUtil.yihuo(info.get(0).getAab121());
                                    AC051 = StringUtil.yihuo(info.get(0).getAab120());
                                    flag = true;
                                }
                            }
                        }
                        if (!flag) {
                            Aaa042 += "0|";
                            Aaa041 += "0|";
                            Aae020 += "0|";
                            Aae022 += "0|";
                            Aae002 += "0|";
                            Aae003 += "0|";
                            Aae080 += "00|";
                            Aae082 += "00|";
                        }
                    }

                    dy1 = sdf.parse(o3.getStr("Aae003"));

                    cp1 = "<CP>" + "<CP01>" + o3.getStr("Aab001") + "</CP01>" + "<CP02>" + o3.getStr("Aab004")
                            + "</CP02>" + "<CP03>" + o3.getStr("Aab004") + "</CP03>" + "<CP04>"
                            + o3.getStr("Aab998") + "</CP04>" + "<CP05>" + dw2type(o3.getStr("Aab019"))
                            + "</CP05>"// --代码不对应，需转换"
                            + "<CP06/><CP07/><CP08>" + sb2type(o3.getStr("Aaa120"))
                            + "</CP08><CP09/><CP10/><CP11/><CP12/><CP13/><CP14/><CP15/>"

                            + "<CP16/><CP17/>"// --代码不对应，需转换"
                            + "<CP18/><CP19/><CP20/><CP21/><CP22/><CP23/><CP24/><CP25/><CP26/><CP27/><CP28/><CP29/>"
                            + "<CP30/><CP31/><CP32/><CP33/><CP34/><CP35/><CP36/><CP37/><CP38/><CP39/><CP40/>" + "<CP41>"
                            + o3.getStr("Aab998") + "</CP41>" + "</CP>" + "<AP>" + "<AP01>" + o3.getStr("Aac147")
                            + "</AP01>" + "<AP02>CHN</AP02>" + "<AP03>" + sb2type(o3.getStr("Aac058")) + "</AP03>"
                            + "<AP04>" + o3.getStr("Aac147") + "</AP04>" + "<AP05>" + o3.getStr("Aac147")
                            + "</AP05><AP06/><AP07/><AP08/>" + "<AP09>" + o3.getStr("Aac003") + "</AP09>" + "<AP10>"
                            + xb2type(o3.getStr("Aac004")) + "</AP10><AP11/><AP12/>" + "<AP13>"
                            + o3.getStr("Aac006") + "</AP13>" + "<AP14>" + o3.getStr("Aae006") + "</AP14>"
                            + "<AP15>" + o3.getStr("Aae007") + "</AP15><AP16/>" + "<AP17>" + o3.getStr("Aae005")
                            + "</AP17><AP18/>" + "<AP19/>"// --代码不对应，需转换"
                            + "<AP20>" + o3.getStr("Aac010") + "</AP20>"
                            + "<AP21/><AP22/><AP23/><AP24/><AP25/><AP26/><AP27/><AP28/><AP29/><AP30/><AP31/>" + "<AP32>"
                            + o3.getStr("Aab301") + "</AP32><AP33/><AP34/><AP35/>" + "<AP36>"
                            + cb2type(o3.getStr("Aac008"), o3.getStr("Aac084")) + "</AP36><AP37/>"// --代码不对应，需转换"
                            + "</AP>" + "<AC>" + "<AC01>" + o3.getStr("Aac147") + "</AC01>" + "<AC02>"
                            + o3.getStr("Aab001") + "</AC02>" + "<AC03>" + o3.getStr("Aab301") + "</AC03>"
                            + "<AC04>" + AC041 + "</AC04>"// --取最新"
                            + "<AC05>" + AC041 + "</AC05>"// --取最新"
                            + "<AC06/><AC07/>" + "</AC>";

                    af1 = "<AF>" + "<AF01>" + sb2type(o3.getStr("Aae140")) + "</AF01>"// --取发送，若有两种险种，发两次？能不能设置为当险种为空时，在循环里加上险种字段"
                            + "<AF02/>" + "<AF03>" + o3.getStr("Aae003") + "01" + "</AF03>"// --最新一次缴存的日期YYYYMMDD，若无"DD"，可送每月1号"
                            + "<AF04>" + o3.getStr("Aae003") + "01" + "</AF04>"// --最新一次缴存的日期YYYYMMDD，若无"DD"，可送每月1号"
                            + "<AF05>" + o3.getStr("Aae041") + "</AF05>" + "<AF06>" + o3.getStr("Aae042")
                            + "</AF06>" + "<AF07>" + Aaa042.substring(0, Aaa042.length() - 1) + "</AF07>"// --12.00%|12.00%|0|0|0
                            + "<AF08>" + Aaa041.substring(0, Aaa041.length() - 1) + "</AF08>"// --12.00%|12.00%|0|0|0
                            + "<AF09>" + Aae020.substring(0, Aae020.length() - 1) + "</AF09>"// 0.01
                            + "<AF10>" + Aae022.substring(0, Aae022.length() - 1) + "</AF10>"// 0.01
                            + "<AF11>" + Aae080.substring(0, Aae080.length() - 1) + "</AF11>"// --不确定，我们要连续24个月的"
                            + "<AF12>" + Aae082.substring(0, Aae082.length() - 1) + "</AF12>"// --不确定，我们要连续24个月的"
                            + "<AF13>" + Aae002.substring(0, Aae002.length() - 1) + "</AF13>"// DD补为01
                            + "<AF14>" + Aae003.substring(0, Aae003.length() - 1) + "</AF14>" + "</AF>";

                    code1Flag = true;

                }
            } else if (!"null".equals(sbxml2)) {
                String b2 = XmlJsonUtil.xml2json(sbxml2);
                JSONObject result2 = JSONUtil.parseObj(b2);
                JSONObject o22 = JSONUtil.parseObj((String) result2.getStr("MsgText"));
                JSONObject o32 = JSONUtil.parseObj((String) o22.getStr("BusiText"));
                recodejson2 = JSONUtil.parseObj((String) o32.getStr("Rst"));
                LoopsCount2 = o32.getInt("LoopCount");

                if (recodejson2.get("Code").equals("0000")) {
                    Aaa042 = "";
                    Aaa041 = "";
                    Aae020 = "";
                    Aae022 = "";
                    Aae002 = "";
                    Aae003 = "";
                    JSONObject o42 = JSONUtil.parseObj((String) o32.getStr("Loops"));
                    List<Object> jsonarray2 = o42.getJSONArray("Loop");
                    String jsonString2 = JSONUtil.toJsonStr(jsonarray2);
                    JSONArray ls2 = JSONUtil.parseArray(jsonString2);
                    List<Info> info2 = new ArrayList<>();
                    ls2.forEach(l -> {
                        Info bean = JSONUtil.toBean(JSONUtil.parseObj(l), Info.class);
                        info2.add(bean);
                    });

                    String strattime2 = "";
                    // strattime2 =
                    // sdf.format(sutil.getMonthDate(sdf.parse(info2.get(0).getAae003()),
                    // 1));//开始月份
                    strattime2 = sdf.format(cal.getTime());// 开始月份
                    List<String> list2 = sutil.getMonths(sdf.format(sutil.getMonthDate(sdf.parse(strattime2), -24)),
                            strattime2);// 24个月之前

                    boolean flag2 = false;
                    List<String> infoReserve2 = new ArrayList<String>();
                    for (int i = list2.size() - 1; i >= 0; i--) {
                        infoReserve2.add(list2.get(i));
                    }
                    for (int k = 0; k < infoReserve2.size(); k++) {
                        flag2 = false;
                        for (int i = 0; i < info2.size(); i++) {
                            if (infoReserve2.get(k).toString().contains(info2.get(i).getAae003())) {
                                Aaa042 += myde.format(Double.parseDouble(info2.get(i).getAaa042()) * 100) + "%|";
                                Aaa041 += myde.format(Double.parseDouble(info2.get(i).getAaa041()) * 100) + "%|";
                                Aae020 += StringUtil.yihuo(info2.get(i).getAae020()) + "|";
                                Aae022 += StringUtil.yihuo(info2.get(i).getAae022()) + "|";
                                Aae002 += info2.get(i).getAae002() + "01|";
                                Aae003 += info2.get(i).getAae003() + "|";
                                Aae080 += jfzt2type(info2.get(i).getAae003(), info2.get(i).getAae002()) + "|";
                                Aae082 += jfzt2type(info2.get(i).getAae003(), info2.get(i).getAae002()) + "|";
                                AC042 = StringUtil.yihuo(info2.get(0).getAab121());
                                AC052 = StringUtil.yihuo(info2.get(0).getAab120());
                                flag2 = true;
                            }
                        }
                        if (!flag2) {
                            Aaa042 += "0|";
                            Aaa041 += "0|";
                            Aae020 += "0|";
                            Aae022 += "0|";
                            Aae002 += "0|";
                            Aae003 += "0|";
                            Aae080 += "00|";
                            Aae082 += "00|";
                        }
                    }

                    dy2 = sdf.parse(o32.getStr("Aae003"));
                    cp2 = "<CP>" + "<CP01>" + o32.getStr("Aab001") + "</CP01>" + "<CP02>" + o32.getStr("Aab004")
                            + "</CP02>" + "<CP03>" + o32.getStr("Aab004") + "</CP03>" + "<CP04>"
                            + o32.getStr("Aab998") + "</CP04>" + "<CP05>" + dw2type(o32.getStr("Aab019"))
                            + "</CP05>"// --代码不对应，需转换"
                            + "<CP06/><CP07/><CP08>" + sb2type(o32.getStr("Aaa120")) + "</CP08>"
                            + "<CP09/><CP10/><CP11/><CP12/>" + "<CP13/><CP14/><CP15/>" + "<CP16/><CP17/>"
                            + "<CP18/><CP19/><CP20/><CP21/><CP22/><CP23/><CP24/><CP25/><CP26/><CP27/><CP28/><CP29/>"
                            + "<CP30/><CP31/><CP32/><CP33/><CP34/><CP35/><CP36/><CP37/><CP38/><CP39/><CP40/>" + "<CP41>"
                            + o32.getStr("Aab998") + "</CP41>" + "</CP>" + "<AP>" + "<AP01>"
                            + o32.getStr("Aac147") + "</AP01>" + "<AP02>CHN</AP02>" + "<AP03>"
                            + sb2type(o32.getStr("Aac058")) + "</AP03>" + "<AP04>" + o32.getStr("Aac147")
                            + "</AP04>" + "<AP05>" + o32.getStr("Aac147") + "</AP05><AP06/><AP07/><AP08/>" + "<AP09>"
                            + o32.getStr("Aac003") + "</AP09>" + "<AP10>" + xb2type(o32.getStr("Aac004"))
                            + "</AP10><AP11/><AP12/>" + "<AP13>" + o32.getStr("Aac006") + "</AP13>" + "<AP14>"
                            + o32.getStr("Aae006") + "</AP14>" + "<AP15>" + o32.getStr("Aae007") + "</AP15>"
                            + "<AP16/>" + "<AP17>" + o32.getStr("Aae005") + "</AP17>" + "<AP18/>" + "<AP19/>"// --代码不对应，需转换"
                            + "<AP20>" + o32.getStr("Aac010") + "</AP20>"
                            + "<AP21/><AP22/><AP23/><AP24/><AP25/><AP26/><AP27/><AP28/><AP29/><AP30/><AP31/>" + "<AP32>"
                            + o32.getStr("Aab301") + "</AP32>" + "<AP33/>" + "<AP34/>" + "<AP35/>" + "<AP36>"
                            + cb2type(o32.getStr("Aac008"), o32.getStr("Aac084")) + "</AP36>"// --代码不对应，需转换"
                            + "<AP37/>" + "</AP>" + "<AC>" + "<AC01>" + o32.getStr("Aac147") + "</AC01>" + "<AC02>"
                            + o32.getStr("Aab001") + "</AC02>" + "<AC03>" + o32.getStr("Aab301") + "</AC03>"
                            + "<AC04>" + AC042 + "</AC04>"// --取最新"
                            + "<AC05>" + AC052 + "</AC05>"// --取最新"
                            + "<AC06/>" + "<AC07/>" + "</AC>";

                    af2 = "<AF>" + "<AF01>" + sb2type(o32.getStr("Aae140")) + "</AF01>"// --取发送，若有两种险种，发两次？能不能设置为当险种为空时，在循环里加上险种字段"
                            + "<AF02/>" + "<AF03>" + o32.getStr("Aae003") + "01" + "</AF03>"// --最新一次缴存的日期YYYYMMDD，若无"DD"，可送每月1号"
                            + "<AF04>" + o32.getStr("Aae003") + "01" + "</AF04>"// --最新一次缴存的日期YYYYMMDD，若无"DD"，可送每月1号"
                            + "<AF05>" + o32.getStr("Aae041") + "</AF05>" + "<AF06>" + o32.getStr("Aae042")
                            + "</AF06>" + "<AF07>" + Aaa042.substring(0, Aaa042.length() - 1) + "</AF07>"// --12.00%|12.00%|0|0|0
                            + "<AF08>" + Aaa041.substring(0, Aaa041.length() - 1) + "</AF08>"// --12.00%|12.00%|0|0|0
                            + "<AF09>" + Aae020.substring(0, Aae020.length() - 1) + "</AF09>"// 0.01
                            + "<AF10>" + Aae022.substring(0, Aae022.length() - 1) + "</AF10>"// 0.01
                            + "<AF11>" + Aae080.substring(0, Aae080.length() - 1) + "</AF11>"// --不确定，我们要连续24个月的"
                            + "<AF12>" + Aae082.substring(0, Aae082.length() - 1) + "</AF12>"// --不确定，我们要连续24个月的"
                            + "<AF13>" + Aae002.substring(0, Aae002.length() - 1) + "</AF13>"// DD补为01s
                            + "<AF14>" + Aae003.substring(0, Aae003.length() - 1) + "</AF14>" + "</AF>";
                    code2Flag = true;
                }
            } else {
                rebocXml = "<?xml version=\"1.0\" encoding=\"GBK\"?><CSPA05>" + headXml
                        + "<REP_MSG><Result>5319001</Result><INF>分行查询公积金、社保、地税、国税信息无结果</INF></REP_MSG></CSPA05>";
            }

            String code = "";
            String msg = "";

            if (recodejson != null && recodejson2 != null) {
                if (recodejson.get("Code").equals("2005") && recodejson2.get("Code").equals("2005")) {
                    code = "5319001";
                    msg = "分行查询公积金、社保、地税、国税信息无结果";
                } else if (recodejson.get("Code").equals("2001") || recodejson2.get("Code").equals("2001")) {
                    code = "5319001";
                    msg = "分行查询公积金、社保、地税、国税信息无结果";
                } else {
                    code = "5390000";
                    msg = "查询成功/接收成功";
                }
            } else if (recodejson == null) {
                if (recodejson2.get("Code").equals("2005")) {
                    code = "5319001";
                    msg = "分行查询公积金、社保、地税、国税信息无结果";
                } else if (recodejson2.get("Code").equals("2001")) {
                    code = "5319001";
                    msg = "分行查询公积金、社保、地税、国税信息无结果";
                } else if (recodejson2.get("Code").equals("0000") && LoopsCount2 == 0) {
                    code = "5319999";
                    msg = "分行查询公积金信息、社保信息、地税信息、国税信息其他错误";// 20211101修改
                } else {
                    code = "5390000";
                    msg = "查询成功/接收成功";
                }
            } else if (recodejson2 == null) {
                if (recodejson.get("Code").equals("2005")) {
                    code = "5319001";
                    msg = "分行查询公积金、社保、地税、国税信息无结果";
                } else if (recodejson.get("Code").equals("2001")) {
                    code = "5319001";
                    msg = "分行查询公积金、社保、地税、国税信息无结果";
                } else if (recodejson.get("Code").equals("0000") && LoopsCount1 == 0) {
                    code = "5319999";
                    msg = "分行查询公积金信息、社保信息、地税信息、国税信息其他错误"; // 20211101修改
                } else {
                    code = "5390000";
                    msg = "查询成功/接收成功";
                }
            }

            rebocXml = "<?xml version=\"1.0\" encoding=\"GBK\"?><CSPA05>" + headXml + "<REP_MSG><Result>" + code
                    + "</Result><INF>" + msg + "</INF><RM>";

            String end = "<RES01_COUNT>0</RES01_COUNT><RES02_COUNT>0</RES02_COUNT><RES03_COUNT>0</RES03_COUNT><RES04_COUNT>0</RES04_COUNT><RES05_COUNT>0</RES05_COUNT><RES06_COUNT>0</RES06_COUNT></RM></REP_MSG></CSPA05>";

            if (code2Flag && code1Flag) {
                if (dy2.after(dy1) && (LoopsCount2 != 0)) {
                    rebocXml = rebocXml + cp2 + "<AF_COUNT>2</AF_COUNT>" + af1 + af2 + end;// 最终报文
                    return rebocXml;
                } else {
                    rebocXml = rebocXml + cp1 + "<AF_COUNT>2</AF_COUNT>" + af1 + af2 + end;// 最终报文
                    return rebocXml;
                }
            } else if (code1Flag && (LoopsCount1 != 0)) {
                rebocXml = rebocXml + cp1 + "<AF_COUNT>1</AF_COUNT>" + af1 + end;// 最终报文
                return rebocXml;
            } else if (code2Flag && (LoopsCount2 != 0)) {
                rebocXml = rebocXml + cp2 + "<AF_COUNT>1</AF_COUNT>" + af2 + end;// 最终报文
                return rebocXml;
            } else {
                rebocXml = rebocXml.substring(0, rebocXml.length() - 4) + "</REP_MSG></CSPA05>";
                return rebocXml;
            }

        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
            return "";
        }
    }

    private Object getAae004() {
        // TODO Auto-generated method stub
        return null;
    }

    private Object getAae002() {
        // TODO Auto-generated method stub
        return null;
    }

    public String sb2type(String sbtype) {
        String boctype = "";
        if (sbtype.equals("01")) {
            boctype = "0";
        } else if (sbtype.equals("02")) {
            boctype = "3";
        } else if (sbtype.equals("03")) {
            boctype = "9";
        } else if (sbtype.equals("04")) {
            boctype = "5";
        } else if (sbtype.equals("05")) {
            boctype = "5";
        } else if (sbtype.equals("06")) {
            boctype = "6";
        } else if (sbtype.equals("07")) {
            boctype = "8";
        } else if (sbtype.equals("08")) {
            boctype = "X";
        } else if (sbtype.equals("09")) {
            boctype = "X";
        } else if (sbtype.equals("10")) {
            boctype = "X";
        } else if (sbtype.equals("11")) {
            boctype = "X";
        } else if (sbtype.equals("12")) {
            boctype = "X";
        } else if (sbtype.equals("13")) {
            boctype = "X";
        } else if (sbtype.equals("14")) {
            boctype = "X";
        } else if (sbtype.equals("15")) {
            boctype = "X";
        } else if (sbtype.equals("16")) {
            boctype = "X";
        } else if (sbtype.equals("17")) {
            boctype = "2";
        } else if (sbtype.equals("90")) {
            boctype = "X";
        } else if (sbtype.equals("99")) {
            boctype = "X";
        } else if (sbtype.equals("0")) {
            boctype = "30";
        } else if (sbtype.equals("1")) {
            boctype = "10";
        } else if (sbtype.equals("110")) {
            boctype = "101";
        } else if (sbtype.equals("120")) {
            boctype = "102";
        } else if (sbtype.equals("170")) {
            boctype = "110";
        } else if (sbtype.equals("")) {
            boctype = "10";
        } else {
            boctype = "";
        }
        return boctype;
    }

    public String dw2type(String sbtype) {
        String boctype = "";
        if (sbtype.equals("10")) {
            boctype = "1";
        } else if (sbtype.equals("30")) {
            boctype = "3";
        } else if (sbtype.equals("50")) {
            boctype = "2";
        } else if (sbtype.equals("55")) {
            boctype = "2";
        } else if (sbtype.equals("56")) {
            boctype = "2";
        } else if (sbtype.equals("57")) {
            boctype = "2";
        } else if (sbtype.equals("70")) {
            boctype = "4";
        } else if (sbtype.equals("91")) {
            boctype = "13";
        } else {
            boctype = "9";
        }
        return boctype;
    }

    public String cb2type(String cbStatus, String isTuixiu) {
        String boctype = "";

        if (cbStatus.equals("0")) {
            boctype = "C0B";
        } else if (cbStatus.equals("4")) {
            boctype = "C0D";
        } else if (cbStatus.equals("1")) {
            if (isTuixiu.equals("1")) {
                boctype = "A0C";
            } else if (isTuixiu.equals("0")) {
                boctype = "A0A";
            }
        }
        return boctype;
    }

    public String xb2type(String sbtype) {
        String boctype = "";

        if (sbtype.equals("0")) {
            boctype = "";
        } else {
            boctype = sbtype;
        }
        return boctype;
    }

    public String jfzt2type(String yjdate, String sjdate) {
        String boctype = "";
        if (yjdate != null && sjdate != null) {
            if (!yjdate.equals("") && !sjdate.equals("")) {
                if (yjdate.equals(sjdate)) {
                    boctype = "02";
                } else {
                    boctype = "06";
                }
            }
        } else {
            boctype = "06";
        }

        return boctype;
    }

}
